package com.tangr.normaladapter.abslistview;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tangr.normaladapter.ViewHolder;

import java.util.List;

/**
 * Created by tangr on 2016/6/7.
 */
public abstract class NormalAdapter<T> extends BaseAdapter{
    protected List<T> mList;
    protected Context mContext;
    private int mLayoutId;

    public NormalAdapter(Context context,List<T> list,int layoutId) {
        this.mContext = context;
        this.mList = list;
        this.mLayoutId = layoutId;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public T getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = ViewHolder.get(mContext,convertView,parent,mLayoutId);
        setView(vh,getItem(position));
        return vh.getConvertView();
    }

    public abstract void setView(ViewHolder vh, T item);
}
